(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('apf.popup.discount.cashPattern',cashPatternController);
	cashPatternController.$inject = [ '$scope', '$q', '$uibModalInstance', 'Constants', 'ajaxServiceFactory', 'dialogsModule', 'gridService', 'modalService', 'layoutConfig', 'validatorConfig', 'authService' ];
	function cashPatternController($scope, $q, $uibModalInstance, Constants, ajaxServiceFactory, dialogsModule, gridService, modalService, layoutConfig, validatorConfig, authService) {
		var ctrl = this;
		ctrl.dialogsModule = dialogsModule;
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.cashPattern = {};
		ctrl.cashPattern.label = "label.cashpattern.";
		
		ctrl.ok = function() {
			if (!dialogsModule.btnCallback || !dialogsModule.btnCallback['ok'] || dialogsModule.btnCallback['ok']([{"cashPattern" : angular.toJson(ctrl.cashPattern)}]) !== false) {
				$uibModalInstance.close();
			}
		};
		
		ctrl.close = function() {
			if (!dialogsModule.btnCallback || !dialogsModule.btnCallback['close'] || dialogsModule.btnCallback['close']() !== false) {
				$uibModalInstance.dismiss();
			}
		};
		
		ctrl.init = function() {
			ctrl.cashPatternTypeOptions =
				[{"label" : "label.cashpattern.dtm", "value" : "DTM"},
				 {"label" : "label.cashpattern.fixdate", "value" : "FIXED-DATE"},
				 {"label" : "label.cashpattern.fixday", "value" : "FIXED-DAY"},
				 {"label" : "label.cashpattern.eod", "value" : "EOD"},
				 {"label" : "label.cashpattern.sod", "value" : "SOD"},
				 {"label" : "label.cashpattern.appimmediately", "value" : "APPIMMEDIATELY"}];
			
			ctrl.monthlyDayOptions =[];
			for(var i = 1 ; i <32 ; i++){
				ctrl.monthlyDayOptions.push({"label" : i, "value" : i});
			}
			ctrl.weeklyDayOptions =
				[{"label" : "label.weeklyday.1", "value" : "1"},
				 {"label" : "label.weeklyday.2", "value" : "2"},
				 {"label" : "label.weeklyday.3", "value" : "3"},
				 {"label" : "label.weeklyday.4", "value" : "4"},
				 {"label" : "label.weeklyday.5", "value" : "5"},
				 {"label" : "label.weeklyday.6", "value" : "6"},
				 {"label" : "label.weeklyday.7", "value" : "7"}];
			if(dialogsModule.params.cashPattern){
				ctrl.cashPattern = angular.fromJson(dialogsModule.params.cashPattern);
			};
		};
	}
})(angular);
